<template>
  <div class="app-container home">
    <div style="background-color: white;padding: 10px;margin-bottom: 20px">

      <div style="margin-bottom: 10px">
        舆情案例库<span class="case_count">{{total}}</span>例
      </div>

      <el-row :gutter="20">
        <el-col :span="16" >
          <el-row style="border-left: 1px solid #ebebeb;border-top: 1px solid #ebebeb;">
            <el-col :span="6" v-for="(item,index) in typeCount" :key="index">
              <div style="text-align: center;padding: 10px;border-right: 1px solid #ebebeb;border-bottom: 1px solid #ebebeb;cursor: pointer;">

                <div style="display: inline-flex">
                  <div style="font-size: 26px !important;color: #333;">
                    {{item.value}}
                  </div>
                  <div style="color: #666;margin-top: 10px">例    </div>
                </div>
                <div style="color: #666;margin-top: 10px">
                  {{item.name}}
                </div>
              </div>

            </el-col>
          </el-row>


        </el-col>

        <el-col :span="8"  >

          <el-form   :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="事件标题" prop="incidentTitle" s>
              <el-input
                style="width: 300px"
                v-model="queryParams.incidentTitle"
                placeholder="请输入事件标题"
                clearable
                size="small"
                @keyup.enter.native="handleQuery"
              >
                <el-button slot="append" icon="el-icon-search" @click="handleQuery"></el-button>
              </el-input>
            </el-form-item>

            <el-form-item label="事件类型" prop="incidentTypeMsg">
              <el-input v-model="queryParams.incidentType" style=" display: none"/>
              <el-select size="small" v-model="queryParams.incidentType" placeholder="请选择事件分类" clearable
                         style="width: 300px">
                <el-option v-for="dict in incidentTypeOptions"
                           :key="dict.dictValue"
                           :label="dict.dictLabel"
                           :value="dict.dictValue"
                           style="width: 100%"/>
              </el-select>
            </el-form-item>


            <el-form-item label="事件主体" prop="incidentSubjectMsg">
              <el-input v-model="queryParams.incidentSubjectMsg" style="display: none"/>
              <el-select size="small" v-model="queryParams.incidentSubjectMsg" placeholder="请选择涉事主体" clearable
                         style="width: 300px">
                <el-option v-for="dict in incidentSubjectOptions"
                           :key="dict.dictValue"
                           :label="dict.dictLabel"
                           :value="dict.dictLabel"
                           style="width: 100%"/>
              </el-select>
            </el-form-item>


          </el-form>
        </el-col>
      </el-row>


    </div>



  <el-divider>案例分析</el-divider>
    <div style="background-color: white;padding: 10px;">

      <div v-loading="loading" v-for="(item,index) in caseList" :key="index"
           :style="{ backgroundColor: isEvenIndex(index) ? '#fbfcfe' : '',padding:'10px',borderBottom: '1px solid #ebebeb' }" >
        <div style="margin-bottom: 5px">
          <el-row>
              <span class="article-title" @click="gotoDetails(item)">{{item.incidentTitle}}</span>
              <el-tag size="small" effect="plain" >{{item.incidentTypeMsg}}</el-tag>
              <el-tag size="small" effect="plain" style="margin-left: 10px">{{item.incidentRootsMsg}}</el-tag>
          </el-row>
        </div>
        <div class="article-content">
          {{item.incidentConcise}}
        </div>
        <div style="font-size: 12px;color: #888888;margin-top:10px;margin-bottom: 20px;">
          <span>发生时间：{{item.occurrenceTime}}</span>
          <span style="margin-left: 10px">发生地点：{{item.provinceMsg}}{{item.cityMsg}}</span>
          <span style="margin-left: 10px">涉事主体：{{item.incidentSubjectMsg}}</span>
        </div>
      </div>



      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

    </div>
    <!-- 添加或修改案例对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="事件标题" prop="incidentTitle">
          <el-input v-model="form.incidentTitle" placeholder="请输入事件标题"/>
        </el-form-item>
        <el-form-item label="事件简介" prop="incidentConcise">
          <el-input v-model="form.incidentConcise" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="事件类型编号" prop="incidentType">
          <el-select v-model="form.incidentType" placeholder="请选择事件类型编号">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="事件类型" prop="incidentTypeMsg">
          <el-input v-model="form.incidentTypeMsg" placeholder="请输入事件类型"/>
        </el-form-item>
        <el-form-item label="事件类型" prop="incidentRoots">
          <el-input v-model="form.incidentRoots" placeholder="请输入事件类型"/>
        </el-form-item>
        <el-form-item label="事件类型" prop="incidentRootsMsg">
          <el-input v-model="form.incidentRootsMsg" placeholder="请输入事件类型"/>
        </el-form-item>
        <el-form-item label="事件主体编号" prop="incidentSubject">
          <el-input v-model="form.incidentSubject" placeholder="请输入事件主体编号"/>
        </el-form-item>
        <el-form-item label="事件主体" prop="incidentSubjectMsg">
          <el-input v-model="form.incidentSubjectMsg" placeholder="请输入事件主体"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="occurrenceTime">
          <el-input v-model="form.occurrenceTime" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="provinceMsg">
          <el-input v-model="form.provinceMsg" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="cityMsg">
          <el-input v-model="form.cityMsg" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="cycleFeatures">
          <el-input v-model="form.cycleFeatures" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="regionFeatures">
          <el-input v-model="form.regionFeatures" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="enabledState">
          <el-input v-model="form.enabledState" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="incidentDetailsOfProcess">
          <el-input v-model="form.incidentDetailsOfProcess" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="incidentDetailsOfHandle">
          <el-input v-model="form.incidentDetailsOfHandle" placeholder="请输入发生时间"/>
        </el-form-item>
        <el-form-item label="发生时间" prop="incidentDetailsOfInspire">
          <el-input v-model="form.incidentDetailsOfInspire" placeholder="请输入发生时间"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {listCase, getCase, delCase, addCase, updateCase, exportCase, getGroupByIncidentRootsMsg} from "@/api/system/case";

  export default {
    name: "Case",
    components: {},
    data() {
      return {
        typeCount:[],
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 案例表格数据
        caseList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          incidentTitle: null,
          incidentConcise: null,
          incidentType: null,
          incidentTypeMsg: null,
          incidentRoots: null,
          incidentRootsMsg: null,
          incidentSubject: null,
          incidentSubjectMsg: null,
          occurrenceTime: null,
          provinceId: null,
          provinceMsg: null,
          cityId: null,
          cityMsg: null,
          cycleFeatures: null,
          regionFeatures: null,
          enabledState: null,
          incidentDetailsOfProcess: null,
          incidentDetailsOfHandle: null,
          incidentDetailsOfInspire: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        incidentTypeOptions: [],
        incidentSubjectOptions: [],
      };
    },
    created() {
      this.getList();
      this.getDicts("event_type").then(response => {
        this.incidentTypeOptions = response.data;
      });
      this.getDicts("incident_subject").then(response => {
        this.incidentSubjectOptions = response.data;
      });
      this.getGroupByIncidentRootsMsg()
    },
    methods: {
      isEvenIndex(index) {
        return index % 2 === 0;
      },
      gotoDetails(obj) {
        this.$router.push({
          path: '/case/details', query: {
            id: obj.id,
            incidentTitle: obj.incidentTitle,
            incidentConcise: obj.incidentConcise,
            incidentTypeMsg: obj.incidentTypeMsg,
            incidentRootsMsg: obj.incidentRootsMsg,
            incidentSubjectMsg: obj.incidentSubjectMsg,
            occurrenceTime: obj.occurrenceTime,
            provinceMsg: obj.provinceMsg,
            cityMsg: obj.cityMsg,
          }
        });
      },
      /** 查询案例列表 */
      getList() {
        this.loading = true;
        listCase(this.queryParams).then(response => {
          this.caseList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getGroupByIncidentRootsMsg() {
        getGroupByIncidentRootsMsg().then(response => {
            this.typeCount=response.data
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          incidentTitle: null,
          incidentConcise: null,
          incidentType: null,
          incidentTypeMsg: null,
          incidentRoots: null,
          incidentRootsMsg: null,
          incidentSubject: null,
          incidentSubjectMsg: null,
          occurrenceTime: null,
          provinceId: null,
          provinceMsg: null,
          cityId: null,
          cityMsg: null,
          cycleFeatures: null,
          regionFeatures: null,
          enabledState: null,
          incidentDetailsOfProcess: null,
          incidentDetailsOfHandle: null,
          incidentDetailsOfInspire: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加案例";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getCase(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改案例";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCase(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addCase(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除案例编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delCase(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有案例数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportCase(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        })
      }
    }
  };
</script>


<style scoped lang="scss">
  .home {
    background-color: white;
    margin: 10px;
  }

  .article-title {
    cursor: pointer;
    font-size: 16px;
    margin-right: 10px;
    color: #1e1e1e;
    margin-bottom: 10px;
  }

  .article-content {
    text-indent: 35px;
    font-size: 14px;
    color: #565A5E;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    white-space: pre-wrap;
    margin-bottom: 10px;
  }

  .case_count {
    color: #3fc3e3;
    font-size: 24px !important;
    margin-right: 5px !important;
    margin-left: 5px !important;
  }
</style>
